package com.lsf.studentmanagerup.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 检查是否登录，登录则跳转到分页查询
 *
 * @author 李树飞
 */
@WebServlet(name = "Servlet", urlPatterns = {"/main", "/index.jsp"})
public class MainServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Object user = request.getSession().getAttribute("user");

        if (null != user) {
            System.out.println("重定向到getUserByPage");
            response.sendRedirect("getUserByPage");
        }else {
            System.out.println("用户没有登录，转发到登录页面");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
